//
//  File.swift
//  DemoTest
//
//  Created by admin on 2022/4/24.
//

import SwiftUI

struct PassOnew: View {
    
    @State private var writingOne = false
    @State private var writingTwo = false
    @State private var writingThree = false
    @State private var writingFour = false
    @State private var writingFive = false
    @State private var writingSix = false
    @State private var canskip = false
    let cursorColor = Color(#colorLiteral(red: 0, green: 0.368627451, blue: 1, alpha: 1))

    var body: some View {
        ZStack {
            Image("diary")
                .overlay(
                    VStack(spacing: 20) {
                        VStack(alignment: .leading){
                            Text("Today is Jenny's birthday. ")
                                .font(.custom("Bradley Hand Bold", size: 30))
                                .offset(x: 10, y: 0)
                                .mask(
                                    HStack{

                                        Rectangle()

                                            .opacity(writingOne ? 1 : 0)
                                            .frame(width: writingOne ? 400 : 0)
                                        Spacer()

                                    }


                                )
                            //                        Rectangle()
                            //                            .fill(cursorColor)
                            //                            .opacity(blinkingCursor ? 1 : 0)
                            //                            .frame(width: 2, height: 14 )
                            //                            .offset(x: 1, y: 1)

                            //                        Rectangle()
                            //                            .fill(cursorColor)
                            //                            .opacity(blinkingCursor ? 1 : 0)
                            //                            .frame(width: 2, height: 24)
                            //                            .offset(x: movingCursor ? 148 : 0)

                        }
                        .onAppear(){
                            withAnimation(.easeInOut(duration: 1)) {
                                writingOne.toggle()
                                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
                                    withAnimation(.easeInOut(duration: 1)) {
                                        writingTwo.toggle()
                                        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
                                            withAnimation(.easeInOut(duration: 1)) {
                                                writingThree.toggle()
                                                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
                                                    withAnimation(.easeInOut(duration: 1)) {
                                                        writingFour.toggle()
                                                        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
                                                            withAnimation(.easeInOut(duration: 1)) {
                                                                writingFive.toggle()
                                                                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
                                                                    withAnimation(.easeInOut(duration: 1)) {
                                                                        writingSix.toggle()
                                                                        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
                                                                            withAnimation(.easeInOut(duration: 1)) {
                                                                                canskip.toggle()
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                        VStack(alignment: .leading) {
                            Text("I want to give her a surprise. ")
                                .font(.custom("Bradley Hand Bold", size: 30))
                                .offset(x: 10, y: 0)
                                .mask(
                                    HStack{

                                        Rectangle()

                                            .opacity(writingTwo ? 1 : 0)
                                            .frame(width: writingTwo ? 400 : 0)
                                        Spacer()
                                    }


                                )

                        }

                        VStack(alignment: .leading) {
                            Text("a birthday cake and birthday ")
                                .font(.custom("Bradley Hand Bold", size: 30))
                                .offset(x: 10, y: 0)
                                .mask(
                                    HStack{

                                        Rectangle()

                                            .opacity(writingThree ? 1 : 0)
                                            .frame(width: writingThree ? 400 : 0)

                                        Spacer()
                                    }


                                )

                        }


                        VStack(alignment: .leading) {
                            Text(" and birthday wishes in sign  ")
                                .font(.custom("Bradley Hand Bold", size: 30))
                                .offset(x: 10, y: 0)
                                .mask(
                                    HStack{

                                        Rectangle()

                                            .opacity(writingFour ? 1 : 0)
                                            .frame(width: writingFour ? 400 : 0)
                                        Spacer()
                                    }


                                )

                        }


                        VStack(alignment: .leading) {
                            Text(" language. I hope she will like  ")
                                .font(.custom("Bradley Hand Bold", size: 30))
                                .offset(x: 10, y: 0)
                                .mask(
                                    HStack{

                                        Rectangle()

                                            .opacity(writingFive ? 1 : 0)
                                            .frame(width: writingFive ? 400 : 0)
                                        Spacer()
                                    }


                                )

                        }


                        VStack(alignment: .leading) {
                            Text("it.                                             ")
                                .font(.custom("Bradley Hand Bold", size: 30))
                                .offset(x: 10, y: 0)
                                .mask(
                                    HStack{

                                        Rectangle()

                                            .opacity(writingSix ? 1 : 0)
                                            .frame(width: writingSix ? 400 : 0)
                                        Spacer()
                                    }


                                )

                        }

                        Spacer()
                            .frame( height:250)

                    }



                )





            //            (a birthday cake and birthday wishes in sign language).
            VStack {
                Spacer()
                Text("Click Screen to next")
                    .font(.custom("Bradley Hand Bold", size: 30))

            }


        }

        .onTapGesture {
            //几秒后执行 跳转
            if canskip {
                 print("xxxxx---Canstep----X")
                if let window = UIApplication.shared.windows.first {
                    window.rootViewController = UIHostingController(rootView: ShoppingVC())
                    window.makeKeyAndVisible()
                }
            }

        }

        .onAppear() {
            withAnimation(.easeInOut(duration: 2)) {

            }
        }

    }
    
 
    
}



struct TestView_Previews: PreviewProvider {
    static var previews: some View {
        PassOnew()
            .previewInterfaceOrientation(.landscapeLeft)
    }
}




